<template>
    <view>
        <at-button @tap="logout" type="primary" v-if="isToken">退出登陆</at-button>
        <at-button @tap="login" type="primary" v-else>登陆</at-button>
    </view>
</template>

<script lang="ts">
import { defineComponent,computed, ComputedRef } from "vue";
import { AtButton } from 'taro-ui-vue3'
import Taro from '@tarojs/taro'

export default defineComponent({
    components:{
        AtButton
    },
    setup(){
        const isToken:ComputedRef<boolean> = computed(()=>Taro.getStorageSync("token"))
        function logout():void{
            Taro.clearStorageSync()
            Taro.reLaunch({
                url:"/pages/login/login"
            })

        }
        function login():void{
            Taro.navigateTo({
                url:"/pages/login/login"
            })
        }
        return {
            logout,
            isToken,
            login
        }
    }
})
</script>

<style>

</style>